<template>
  <div>
    <el-result icon="success" title="购买成功">
      <template slot="extra">
        在{{count}}秒后跳转主页，若没有跳转请点击按钮
        <el-button type="primary" size="medium" @click="jump">Click</el-button>
      </template>
    </el-result>
  </div>
</template>

<script>
export default {
  name: "completed",
  data() {
    return {
      count: 3,
      timer: null
    }
  },
  methods: {
    timeJump(){
      this.timer = setInterval(() => {
        if(this.count === 0){
          clearInterval(this.timer)
          this.timer = null
          this.jump()
        }else{
          this.count--
        }
      }, 1000)
    },
    jump(){
      this.$router.push({
        path:'/home'
      })
    }
  },
  created() {
    this.timeJump()
  }
}
</script>

<style scoped>

</style>